package cn.xiongxf.service.impl;

import cn.xiongxf.domain.MessageStation;
import cn.xiongxf.dto.MessageStationDto;
import cn.xiongxf.mapper.MessageStationMapper;
import cn.xiongxf.service.IMessageStationService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiongxiaofu
 * @since 2022-08-15
 */
@Service
public class MessageStationServiceImpl extends ServiceImpl<MessageStationMapper, MessageStation> implements IMessageStationService {

    @Override
    public void saveMessageStation(MessageStationDto dto) {
        // 遍历，针对每个用户保存站内消息
        Date date = new Date();
        dto.getUserIds().forEach(userId -> {
            MessageStation messageStation = new MessageStation();
            messageStation.setTitle(dto.getTitle());
            messageStation.setContent(dto.getContent());
            messageStation.setType(dto.getType());
            messageStation.setSendTime(date);
            messageStation.setIsread(0);
            messageStation.setUserId(userId);
            insert(messageStation);
        });
    }
}
